package com.songlanyun.modules.supplychainapi.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapUtil;
import com.songlanyun.common.supplychainapi.aftersale.ApiAfterSaleCommon;
import com.songlanyun.common.supplychainapi.aftersale.model.AfterSaleInfo;
import com.songlanyun.common.supplychainapi.aftersale.model.AfterSaleList;
import com.songlanyun.common.supplychainapi.order.ApiOrderCommon;
import com.songlanyun.common.supplychainapi.order.model.*;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("admin/supplychain/after/sale")
public class SupplyChainAfterSaleAdminController extends AbstractController {

    @Resource
    private ApiAfterSaleCommon apiAfterSaleCommon;

    /**
     * 售后列表V2
     */
    @GetMapping("afterSaleList")
    public R listErrorNew(@RequestParam Map<String, Object> params) {
        AfterSaleList afterSaleList = apiAfterSaleCommon.afterSaleList(params);
        List<AfterSaleList.List> list = CollectionUtil.list(false, afterSaleList.getList());
        return R.ok().put("page", new PageUtils(list, afterSaleList.getCount(),
                MapUtil.getInt(params, "limit", 10),
                MapUtil.getInt(params, "page", 1)));
    }

    /**
     * 售后详情V2
     */
    @GetMapping("afterSaleInfo/{id}")
    public R listErrorInfo(@PathVariable("id") String id) {
        AfterSaleInfo afterSaleInfo = apiAfterSaleCommon.afterSaleInfo(id);
        return R.ok().put("data", afterSaleInfo);
    }

}
